﻿<%@ Page Title="" Language="C#" MasterPageFile="~/GUI/User/UserChiTiet.master" AutoEventWireup="true" CodeBehind="BaiHat.aspx.cs" Inherits="ProjectWebNhac.GUI.User.BaiHat1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script src="js/FancyBox/source/jquery.fancybox.js" type="text/javascript"></script>
    <link href="js/FancyBox/source/jquery.fancybox.css" rel="stylesheet" type="text/css" />
    <script src="js/FancyBox/source/jquery.fancybox.pack.js" type="text/javascript"></script>
    <script src="js/FancyBox/lib/jquery.mousewheel-3.0.6.pack.js" type="text/javascript"></script>
    <script src="js/main.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var tempSong = '';

            $('.nologin').showPopup({
                top: 50,
                closeButton: ".close_popup",
                scroll: false,
                onClose: function () {
                }
            });
            $(".add").fancybox({
                'scrolling': 'no',
                'titleShow': false,
                width: 440,
                height: 340,
                'onClosed': function () {
                    $("#login_error").hide();
                }
            });
            $('.add').on("click", function () {
                tempSong = $(this).text();
            });
            var dropPlaylist = $('#<%=dropPlaylist.ClientID %>');
            $("#btnAdd").on("click", function () {
                if (dropPlaylist.val() == "-1") {
                    alert("Vui lòng chọn playlist");
                } else {
                    AddtoPlaylist();
                }
            });
            $("#btnCreate").on("click", function () {

                if ($('#txtPlaylist').val() == "" || $('#txtPlaylist').val() == null) {
                    alert("Vui lòng đặt tên playlist");
                } else {
                    CreateNewPL();
                }

            });
            function AddtoPlaylist() {
                var data = "{ 'MaPL': '" + dropPlaylist.val() + "','MaBaiHat':'" +
                 tempSong + "'}";
                $.ajax({
                    type: "POST",
                    url: "BaiHat.aspx/AddPlayList",
                    data: data,
                    contentType: "application/json",
                    dataType: "json",
                    success: function (msg) {
                        if (msg.d) {
                            alert("Thêm bài hát thành công");
                            $.fancybox.close();
                        } else {
                            alert("Bài hát này đã tồn tại");
                        }


                        // Replace the div's content with the page method's return.

                    }
                });
            }
            var taikhoan = $('#<%=txtUserName.ClientID%>');
            function CreateNewPL() {
                var data = "{ 'tenPlaylist': '" + $('#txtPlaylist').val() + "','taikhoan':'" +
                 taikhoan.val() + "'}";
                $.ajax({
                    type: "POST",
                    url: "BaiHat.aspx/CreateNewPL",
                    data: data,
                    contentType: "application/json",
                    dataType: "json",
                    success: function (msg) {
                        if (msg.d != "failed") {
                            alert("Thêm playlist thành công");
                            dropPlaylist.append("<option value='" + msg.d +
                            "'>" + $('#txtPlaylist').val() + "</option>");
                            $('#txtPlaylist').val();
                            $.fancybox.close();
                        } else {
                            alert("Tên playlist này đã tồn tại");
                        }

                    }
                });
            }
        });
    </script>
<div class="span9 news no-margin homepage">
                        <div class="main-top span9 tracks-page">
                            <div class="span9 no-margin">
                                <h1>Bài Hát</h1>
                                <div class="options-line">
                                    <div class="breadcrumb-container">
                                        <ul class="breadcrumb">
                                            <li><a href="TrangChu.aspx">Trang Chủ</a> <span class="divider">»</span></li>
                                            <li class="active">Bài Hát</li>
                                        </ul>
                                    </div>
                                    <div class="tabs hidden-phone">
                                        <a href="BaiHat.aspx" class="active">Bài Hát</a>
                                        <a href="Album.aspx">Album</a>
                                        <a href="CaSi.aspx">Ca Sĩ</a>
                                        <a href="BXH.aspx">BXH</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="tracks span9">

                            <div class="letter-search">
                                <ul>
                                    <asp:Repeater ID="reTheLoai" runat="server">
                                    <ItemTemplate>
                                    <ul>
                                    <li><a href="BaiHat.aspx?MaTheLoai=<%#Eval("MaTheLoai") %>"><%#Eval("TenTheLoai") %></a></li>
                                    </ul>
                                    </ItemTemplate>
                                    </asp:Repeater>
                                    
                                </ul>
                            </div>

                            <h1>Bài Hát</h1>
                            <hr/>
                        <asp:Repeater ID="reBaiHat" runat="server" OnItemDataBound="reBaiHat_ItemDataBound" OnItemCommand="reBaiHat_ItemCommand" >
                           <ItemTemplate>
                         <div class='track-line'>
                                <div class='span6 no-margin'>
                                   
                                    <div class="jp-audio custom" id="jp_container_1">
                                        <div class="jp-type-single">
                                            <div class="jp-gui jp-interface">
                                                
                                                <div class='name'>
                                                    <div class="jp-title">
                                                        <ul>
                                                            <li><a href="ChiTietBaiHat.aspx?MaBH=<%#Eval("MaBaiHat") %>"><%#Eval("TenBaiHat") %></a> </li>
                                                            <li>Trình bày : 
                                                                <asp:Repeater ID="reDSCaSiBaiHat" runat="server">
                                                                <ItemTemplate>
                                                                    <a href="ChiTietCaSi.aspx?MaCS=<%#Eval("MaCaSi") %>"><%#Eval("TenCaSi")%>,</a>  
                                                                </ItemTemplate>
                                                                </asp:Repeater>
                                                                </li>
                                                            <li>Đăng bởi : <a href="#"><%#Eval("TaiKhoan") %></a> | Ngày đăng:<%#Eval("NgayThem", "{0:dd-MM-yyyy}")%>| Lượt nghe: <%#Eval("LuotNghe") %></li>
                                                        </ul>
                                                    </div>
                                                    
                                                </div>
                                                <div class="right" style="width: 50px;">
                                            <%if (Session["ThanhVien"] != null)
                                              {
                                                %>
                                                 <a href='#playlistAdd' class='add'><%#Eval("MaBaiHat") %></a>
                                                <%  
                                              }
                                              else
                                              { %>
                                           <a  href="#popup_login" class='nologin'><%#Eval("MaBaiHat") %></a>
                                           <%} %>
                                            <asp:ImageButton ID="imDown" CommandArgument='<%#Eval("LinkBaiHat") %>' CommandName="download" runat="server" ImageUrl="img/down.png" style="margin-top: 7px;width: 16px;"></asp:ImageButton>
                                        
                                        </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                
                            </div>
                           </ItemTemplate>
                           </asp:Repeater>


                        </div>



                        <div class="standard-pagination">
                            <ul>
                                <%--<li class="active"><a href="#" class="btn">1</a></li>
                                <li><a href="#" class="btn">2</a></li>--%>
                                
                                <asp:Literal ID="liPage" runat="server"></asp:Literal>
                            </ul>
                        </div>
                         <asp:TextBox style="display:none" ID="txtUserName" runat="server" Text=""></asp:TextBox>
                        
                      
                            <div style="display:none;width:300px;height:200px" id="playlistAdd" >
	
	    	<p id="login_error">Thêm bài hát vào playlist</p>
		<p>
			<label for="login_name" style="width:100px;float:left">Chọn playlist: </label>
            <asp:DropDownList ID="dropPlaylist" style="margin-top: -3px;width: 190px;" runat="server">
            </asp:DropDownList>
		</p>
		<p>
			<input type="button" class="registration btn btn-blue" value="Thêm" id="btnAdd" />
		</p>
	    <p>
            <label for="login_name" style="width:80px;float:left">Tên Playlist </label>
            <input type="text" id="txtPlaylist"/>
        </p>
        <p>
			<input type="button" class="registration btn btn-blue" value="Tạo mới playlist" id="btnCreate" />
		</p>
</div>
                   
                    </div>
                  
</asp:Content>
